package com.hup.winHolderService.ws.tomcat;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;

/**
 * tomcat websocket api 配置
 *
 * @author hugan
 * @date 2023/10/8
 */
@Configuration
public class TomcatWebsocketConfig {

    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

    @Bean
    public ServletServerContainerFactoryBean servletServerContainerFactoryBean() {
        ServletServerContainerFactoryBean res = new ServletServerContainerFactoryBean();
        //消息长度,详解在 TomcatWebsocketClient.onMessage
        res.setMaxTextMessageBufferSize(20);//1024=1K个中英文字符
        res.setMaxBinaryMessageBufferSize(1024);//20 * 1024 * 1024=20M个byte
        return res;
    }


}
